package link.cocoon.api.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javax.annotation.Resource;
import link.cocoon.api.blog.mapper.ArticleApiService;
import link.cocoon.blog.entity.Article;
import link.cocoon.blog.service.ArticleService;
import link.cocoon.common.resp.Resp;
import link.cocoon.common.resp.RespData;
import link.cocoon.common.resp.RespPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/blog")
public class BlogApiController {

  @Resource
  private ArticleApiService articleApiService;

  @GetMapping("/content/{id:\\d+}")
  public Resp getById(@PathVariable Long id) {
    String content = articleApiService.getContentById(id);
    return RespData.success(content);
  }

  @GetMapping("/page")
  public Resp page(long page, long size) {
    IPage<Article> iPage = articleApiService.page(new Page<>(page, size));
    return RespPage.success(iPage);
  }

}
